package com.zrrd.blog.question.api;

import com.zrrd.blog.api.entities.Question;
import com.zrrd.blog.question.service.IQuestionService;
import com.zrrd.blog.util.base.BaseRequset;
import com.zrrd.blog.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "问题管理",description = "问题管理，不需要登录")
@RestController
@RequestMapping("/api/question")
public class ApiQuestionController {
    @Autowired
    private IQuestionService questionService;

    @ApiOperation("分页查询热门问题列表")
    @PostMapping("/hot")
    public Result findHotList(@RequestBody BaseRequset<Question> request){
        return questionService.findHotList(request);
    }

    @ApiOperation("分页查询最新问题列表")
    @PostMapping("/new")
    public Result findNewList(@RequestBody BaseRequset<Question> request){
        return questionService.findNewList(request);
    }

    @ApiOperation("分页查询未解决问题列表")
    @PostMapping("/wait")
    public Result findWaitList(@RequestBody BaseRequset<Question> request){
        return questionService.findWaitList(request);
    }

    @ApiOperation("根据标签id查询下面的问题列表")
    @PostMapping("/list/{labelId}")
    public Result findListByLabelId(@RequestBody BaseRequset<Question> req, @PathVariable("labelId") String labelId){
        return questionService.findListByLabelId(req,labelId);
    }

    @ApiOperation("根据问题id查询问题详情")
    @GetMapping("/{id}")
    public Result view(@PathVariable("id" ) String id){
        return questionService.findById(id);
    }

    @ApiOperation("更新浏览次数接口")
    @PutMapping("/viewcount/{id}")
    public Result updateViewCount(String id){
        return questionService.updateViewCount(id);
    }

}
